package ru.jexp.rcp.supply.beans.ek.n;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.IManagedForm;

import ru.jexp.rcp.supply.mui.JExpSupplyMessages;

public class RowFormDialog extends FormDialog
{
	private IFormPart[] parts;
	private String title;
	private ImageDescriptor icon;

	public RowFormDialog(Shell shell, IFormPart part)
	{
		this(shell, new IFormPart[] { part });
	}

	public RowFormDialog(Shell shell, IFormPart[] parts)
	{
		super(shell);
		this.parts = parts;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}
	
	public void setImageDescriptor(ImageDescriptor icon)
	{
		this.icon = icon;
	}

	@Override
	protected void configureShell(Shell newShell)
	{
		super.configureShell(newShell);
		newShell.setText(title);
		newShell.setImage(icon.createImage());
	}

	@Override
	protected void createFormContent(IManagedForm mform)
	{
		for (int i = 0; i < parts.length; i++)
		{
			mform.addPart(parts[i]);
		}
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent)
	{
		createButton(parent, IDialogConstants.OK_ID, JExpSupplyMessages.Global_button_add, true);
		createButton(parent, IDialogConstants.CANCEL_ID, JExpSupplyMessages.Global_button_cancel, false);
	}
}
